module.exports = function ($scope, toaster, $modalInstance, view, typelist, device_code, add, del) {

	$scope.ok = function () {
		$modalInstance.close();
	};

	$scope.cancel = function () {
		$modalInstance.dismiss('cancel');
	};

	typelist.save({'view': view, 'device_code': device_code}, function(res){
		if (res.errcode === 0) {
			$scope.objs = res.data;
		} else {
			alert(res.errmsg);
		}
	});

	$scope.selection = function($event, obj){
		var para = {
			'device_code': device_code,
			'ticket_type': obj.CODE,
			'ticket_type_attr': obj.type_attr
		};
		if($event.target.checked){
			add.save(para, function (res) {
				if (res.errcode === 0) {
					toaster.success({ title: '', body: '添加成功！' })
				} else {
					toaster.error({ title: '', body: '添加失败！' })
				}
			});

		} else {
			del.save(para, function (res) {
				if (res.errcode === 0) {
					toaster.success({ title: '', body: '删除成功！' })
				} else {
					toaster.error({ title: '', body: '删除失败！' })
				}
			});
		}


	};
};